<%@ include file="/common/taglibs.jsp"%>
<%@ page import="com.cip.admin.model.User"%>
<%@ page import="java.util.List"%>
<%@ page import="com.cip.common.util.SecurityUtil"%>
<%
String name = (String)request.getAttribute("name");
List<User> listofSuggests=SecurityUtil.getListofSuggests();
%>
<div id="box" style="border: 1px solid #D2D2D2; margin-top: 5px; border-radius: 5px;">
	<div class="top_area">Search Friends</div>
	<div>
		<input type="text" style="width: 210px;" properties="Search"
			id="searchName" /><img src="/images/cip/common/1357060319_find.png"
			onclick="javascript:searchFriend();"></a>
	</div>
	<div style="overflow-y: auto; height: 250px; margin-top: 3px;">
		<div id="searchFriends">
			<% for(User user:listofSuggests){ %>
			<div style="padding-left: 5px;">
				<table width="100%">
					<tr>
						<td align="left"><img style=""
							src="<s:property value="profilePath"/>" alt="" height="50" />
							&nbsp; <strong style="vertical-align: middle"><%=user.getFirstName()%><%=user.getLastName()%></strong>
						</td>
						<td style="vertical-align: middle"><a
							href="/saveOrUpdateFriends?method=saveOrUpdateFriends&userName=<%=user.getUsername()%>" />Add</a></td>
					</tr>
				</table>
			</div>
			<br />
			<%} %>
		</div>
	</div>
</div>
<script>
function searchFriend(){
	var searchName = document.getElementById("searchName").value;
	jQuery.ajax({
	  url: "/searchFriend?method=searchFriend&searchName="+searchName,
	  cache: false,
	  dataType: "json",
	  success: function(data) {
		var html_str = "";	  
		jQuery.each(data.userName, function(i,item){
			if (item){
				html_str = html_str + '<div style="padding-left:5px;"><table width="100%"><tr><td align="left"><img style="" src="'+item.path+'" alt="" height="50" /> &nbsp; <strong style="vertical-align:middle" >'+item.user  					                     						
									+'</strong></td><td style="vertical-align:middle" ><a href="/saveOrUpdateFriends?method=saveOrUpdateFriends&userName='+item.user+'" />Add</a></td></tr></table></div><br/>';
			}
		}		
		);		
		document.getElementById("searchFriends").innerHTML = html_str;
	  }
	});
}
</script>